package com.example.servicebase.exceptionhandler;

import com.example.commonutils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @ClassName GlobalExceptionHandler
 * @Author: wx
 * @Create: 2022-10-29  20:18
 * @Description TODO
 * @Version: 1.0
 **/
@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    //自定义异常处理
    @ExceptionHandler(MusicException.class)
    @ResponseBody
    public R error(MusicException e){
        e.printStackTrace();
        log.error(e.getMsg());
        return R.error(e.getMsg(),e.getCode());
    }
}
